/**
 * 
 */
package com.ssh.common.servlet;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.PropertyConfigurator;

import com.ssh.common.log.LogFactory;
import com.ssh.common.log.LogName;


/**
 * @author zengyuanhui
 *
 */
public class InitServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2982978452137370175L;
	/**
	 * Constructor of the object.
	 */
	public InitServlet() {
		super();
		//System.out.println(this.getClass()+" InitServlet -------------");
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		//System.out.println(this.getClass()+" destroy  -------------");
	}

	public String getServletInfo() {
		return "This is my default servlet created by Eclipse";
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		printInfo("log4j初始化");
		String prefix = getServletContext().getRealPath("/"); 
		String conFile = getServletConfig().getInitParameter("log4j-config-file");
		System.setProperty("log-home",getServletConfig().getInitParameter("log-home")); 
		try{
			PropertyConfigurator.configure(prefix + conFile);
		}catch(Exception e){
				e.printStackTrace();
		}
		LogFactory.getDefaultLog().debug("log4j初始化 "+getServletConfig().getInitParameter("log-home"), LogName.SYSTEM);
		getServletContext().setAttribute("ROOT", getServletConfig().getInitParameter("ROOT"));
		//getServletContext().setAttribute("UPLOADIMAGE", getServletConfig().getInitParameter("UPLOADIMAGE"));
	}
	private void printInfo(String msg){ 
		LogFactory.getDefaultLog().debug(msg, LogName.SYSTEM);
		
	}
}
